package edu.xja.controller;

import edu.xja.entity.Admin;
import edu.xja.service.AdminService;
import edu.xja.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/adminLogin")
public class AdminLoginController extends HttpServlet {
    private AdminService adminService=new AdminServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String adminName=request.getParameter("adminName");
        String adminPass=request.getParameter("adminPass");

        Admin admin = adminService.adminLogin(adminName, adminPass);
        if(null!=admin){
            System.out.println("登录成功");
            request.getSession().setAttribute("login_admin",admin);
            request.getRequestDispatcher("/index.jsp").forward(request,response);
            return;
        }

        System.out.println("登录失败");
        request.setAttribute("tip_info","用户名或者密码错误！！！");
        request.getRequestDispatcher("/admin_login.jsp").forward(request,response);
    }


}
